<template>
  <a-card :bordered="false">

    <div class="table-page-search-wrapper">
      <a-form-model layout="inline" ref="ruleForm" :model="queryParam">
        <z-form-item :datas="fieldArr" :form="queryParam" :gutter="24" :toggle="toggleSearchStatus">
          <a-col :span="4" slot="submit-action">
            <a-space :size="6">
              <a-button type="primary" icon="search" @click="onQuery">查询</a-button>
              <a-button icon="reload" @click="onResetForm">重置</a-button>
              <a @click="toggleSearchStatus = !toggleSearchStatus">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </a-space>
          </a-col>
        </z-form-item>
      </a-form-model>
    </div>
    <a-button style="margin-bottom: 20px" type="primary" @click="readAllBtn">一键已读</a-button>
    <z-table
      ref="table"
      bordered
      rowKey="id"
      :showAlert="false"
      :showSelection="true"
      :columns="columns"
      :dataSource="pageData"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @selectedRow="onSelectedRow"
      @change="onTableChange">
      <span slot="action" slot-scope="text, record">
        <a @click="showAnnouncement(record)">查看</a>

        <a> {{  }} </a>
      </span>
    </z-table>
    <show-announcement ref="ShowAnnouncement"></show-announcement>
    <dynamic-notice ref="showDynamNotice" :path="openPath" :formData="formData"/>
  </a-card>
</template>

<script>
import {getAction, putAction} from '@/api/manage'
import ShowAnnouncement from '@/components/tools/ShowAnnouncement'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import DynamicNotice from '../../components/tools/DynamicNotice'
import {listFor,listForm} from "@views/sjsk/modules/list";
import {backlogListCount, getSuperviseCount, SuperviseList} from "@api/sjsk/specialist";
import {readAll} from "@api/sjsk/information";
export default {
  name: "UserMyInform",
  mixins: [listFor,listForm],
  components: {
    DynamicNotice,
    ShowAnnouncement
  },
  data () {
    return {
      fieldArr: [
        {label: '消息标题', prop: 'sendTitle', tagType: 'input',span: 5},
        {label: '消息类型', prop: 'sendType', tagType: 'dict-select', span: 5,dictOptions:[{text:'系统消息',value:'1'},{text:'短信消息',value:'2'}]},
        {label: '发布人', prop: 'createBy', tagType: 'input', span: 5},
        {label: '阅读状态', prop: 'readFlag', tagType: 'dict-select', span: 5,dictOptions:[{text:'未读',value:'0'},{text:'已读',value:'1'}]},
        {label: '发布时间', prop: 'sendDate', tagType: 'date-picker', span: 5,toggle: false}
      ],
      description: '系统通告表管理页面',
      queryParam: {
        personnelId:1
      },
      selectedRowKeys:[],
      count:{},
      columns: [
        {
          title: '消息标题',
          align: "center",
          dataIndex: 'sendTitle'
        }, {
          title: '消息内容',
          align: "center",
          dataIndex: 'sendContent',
          // customRender: function (text) {
          //   if (text == '1') {
          //     return "通知公告";
          //   } else if (text == "2") {
          //     return "系统消息";
          //   } else {
          //     return text;
          //   }
          // }
        },
        {
          title: '消息类型',
          align: "center",
          dataIndex: 'sendType',
          customRender:function (text) {
            if(text=== '1'){
              return "系统消息";
            }else if(text=== '2'){
              return "短息消息";
            } else {
              return text;
            }
          }
        },
        {
          title: '发布人',
          align: "center",
          dataIndex: 'createBy'
        },
        {
          title: '发布时间',
          align: "center",
          dataIndex: 'sendDate',
          // customRender:function (text) {
          //   if(text=='L'){
          //     return "低";
          //   }else if(text=="M"){
          //     return "中";
          //   }else if(text=="H"){
          //     return "高";
          //   } else {
          //     return text;
          //   }
          // }
        }, {
          title: '阅读状态',
          align: "center",
          dataIndex: 'readFlag',
          customRender:function (text) {
            if(text=='0'){
              return "未读";
            }else if(text=="1"){
              return "已读";
            } else {
              return text;
            }
          }
        },{
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        // list: "/sys/sysAnnouncementSend/getMyAnnouncementSend",
        list: "/sjsk-system/sys/sysAnnouncementSend/getMyAnnouncementSend",
        editCementSend:"sys/sysAnnouncementSend/editByAnntIdAndUserId",
        readAllMsg:"sys/sysAnnouncementSend/readAll",
      },
      loading:false,
      openPath:'',
      formData:''
    }
  },
  async mounted() {
    this.onQuery()
    this.getSuperviseCount()
  },
  methods: {
    onSelectChange(selectedRowKeys, selectionRows) {
      console.log(selectedRowKeys,selectionRows)
      this.selectedRowKeys = selectedRowKeys;
      // this.selectionRows = selectionRows;
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    onSelectedRow(keys) {
      this.selectKeys = keys
      this.isDisabled = keys.length <= 0
    },
    onResetForm() {
      delete this.queryParam.sendTitle
      delete this.queryParam.sendType
      delete this.queryParam.createBy
      delete this.queryParam.readFlag
      delete this.queryParam.sendDate
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.refreshTable()
      // this.$refs.ruleForm.ruleForm()
    },
    renovate(){
      this.refreshTable()
    },
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    readAllBtn(){

      readAll({id:this.selectedRowKeys.toString()}).then(ser => {
        if (ser.success){
          this.$message.success('全部已读');
          this.refreshTable()
        }
      }).catch(err =>{

      })
    },
    getSuperviseCount(){
      backlogListCount().then(ser => {
        console.log(ser)
        this.count = ser.result
        console.log(this.count)
      }).catch(err => {
        console.log(err)
      })
    },
    handleDetail: function(record){
      this.$refs.sysAnnouncementModal.detail(record);
      this.$refs.sysAnnouncementModal.title="查看";
    },
    showAnnouncement(record){
      record.readFlag = 1
      // putAction(this.url.editCementSend,{anntId:record.anntId}).then((res)=>{
      //   if(res.success){
      //     this.loadData();
      //     this.syncHeadNotic(record.anntId)
      //   }
      // });
      if(record.openType==='component'){
        this.openPath = record.openPage;
        this.formData = {id:record.busId};
        this.$refs.showDynamNotice.detail();
      }else{
        this.$refs.ShowAnnouncement.detail(record);
      }
    },
    syncHeadNotic(anntId){
      getAction("sys/annountCement/syncNotic",{anntId:anntId})
    },

    onQuery() {
      this.pageFilter.pageNo = 1
      console.log(this.form)
      this.refreshTable()
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          console.log(this.queryParam)
        } else {
          return false
        }
      })
    },
    refreshTable() {
      let form = Object.assign({}, this.queryParam, this.pageFilter)
      this.loading = true
      getAction(this.url.list, form).then((res) => {
        if (res.success) {
          this.getSuperviseCount()
          this.pageData = res.result;
        }else{
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    // readAll(){
    //   var that = this;
    //   that.$confirm({
    //     title:"确认操作",
    //     content:"是否全部标注已读?",
    //     onOk: function(){
    //       putAction(that.url.readAllMsg).then((res)=>{
    //         if(res.success){
    //           that.$message.success(res.message);
    //           that.loadData();
    //           that.syncHeadNotic();
    //         }
    //       });
    //     }
    //   });
    // },
  }
}
</script>
<style scoped>
.ant-card-body .table-operator{
  margin-bottom: 18px;
}
.anty-row-operator button{margin: 0 5px}
.ant-btn-danger{background-color: #ffffff}z

                                          .ant-modal-cust-warp{height: 100%}
.ant-modal-cust-warp .ant-modal-body{height:calc(100% - 110px) !important;overflow-y: auto}
.ant-modal-cust-warp .ant-modal-content{height:90% !important;overflow-y: hidden}
</style>